package com.lovo.project.servlet.employ;

import com.lovo.project.exception.OurException;
import com.lovo.project.model.EmployeeDO;
import com.lovo.project.service.EmployService;
import com.lovo.project.service.impl.EmployServiceImpl;
import com.lovo.project.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AddEmployServlet",value = "/employ/addEmploy")
public class AddEmployServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
        Integer shopId=Integer.parseInt(request.getParameter("shopId"));
        String name=request.getParameter("employName");
        String position=request.getParameter("employPosition");
        String phone=request.getParameter("employPhone");
        EmployeeDO ed=new EmployeeDO();
        ed.setShopId(shopId);
        ed.setEmployName(name);
        ed.setEmployPosition(position);
        ed.setEmployPhone(phone);
        EmployService service=new EmployServiceImpl();
        service.insertEmploy(ed);
        response.getWriter().print(ResultVO.success().toJson());
        }catch (OurException e){
            response.getWriter().print(ResultVO.fail(e.getCodeEnum()));
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
